package com.ta.controller;

import com.ta.pojo.Product;
import com.ta.service.ProductService;
import com.ta.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("product")
public class ProductController extends BaseController {
    @Autowired
    public ProductService productService;

    /**
     * 热销榜请求
     * @return
     */
    @RequestMapping("find_by_priority")
    public JsonResult<List<Product>> findByPriority(){
        List<Product> productList = productService.findByPriority();
        return new JsonResult<>(200,productList);
    }

    /**
     * 最新榜请求
     * @return
     */
    @RequestMapping("find_by_time")
    public JsonResult<List<Product>> findByTime(){
        List<Product> productList = productService.findByTime();
        return new JsonResult<>(200,productList);
    }

    /**
     * 商品详情请求
     * @param id
     * @return
     */
    @RequestMapping("find_by_id")
    public JsonResult<Product> findById(Integer id){
        Product product = productService.finyById(id);
        return new JsonResult<>(200,product);
    }
}
